<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="../../../common/include.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<jsp:include page="../../../common/head.jsp">
			 <jsp:param name="_spPage" value="true"/>
			 <jsp:param name="_useCalendar" value="true"/>
			 <jsp:param name="_useSuggest" value="true"/>
			 <jsp:param name="_useOrgSuggest" value="true"/>
			 <jsp:param name="_useEmpSuggest" value="true"/>
		</jsp:include>

		<title>员工信息查询</title>
		<script language="JavaScript">   
			function checkAllEmp()
			{
				var checkedcount = 0;
				var checkObj = document.getElementsByName("employeeId");
				for (var i = 0; i < checkObj.length; i++) {
					if (checkObj[i].checked) {
						checkedcount++;
					}
				}
				if (checkedcount == checkObj.length) {
					for (var i = 0; i < checkObj.length; i++) {
						checkObj[i].checked = false;
						employeeSelect(checkObj[i]);
					}
				} else {
					for (var i = 0; i < checkObj.length; i++) {
						checkObj[i].checked = true;
						employeeSelect(checkObj[i]);
					}
				}
			}
			function showData(employeeId)
			{
				ModalWindow("showEmployee.do?employeeId="+employeeId,0,0);
			}
			function selectData(returnData)
			{
				//0员工ID,1员工代码,2员工姓名,3员工性别,4身份证号,5单位ID,6单位名称,7部门ID,8部门名称,9岗位名称,10出生日期,11在岗情况,12员工身份
				window.top.returnValue=returnData;
				window.top.close();
			}
			function employeeSelect(objCheckbox)
			{
				var employeeInfo = $(objCheckbox).val().split(",");
				var employeeId=employeeInfo[0];
				var employeeCode=employeeInfo[1];
				var employeeName=employeeInfo[2];

				if($(objCheckbox).attr("checked")=="checked")
				{
					if(parent.selectedEmployee.indexOf(employeeId)==-1)
					{
						parent.selectedEmployee=parent.selectedEmployee+$(objCheckbox).val()+";";
						var html="<span id=\""+employeeId+"\" title=\"点击取消选择该员工\" class=\"empSpan\">"+employeeName+"&nbsp;</span>";
						$("#empTd").append(html);
					}
				}
				else
				{
					parent.selectedEmployee=parent.selectedEmployee.replace($(objCheckbox).val()+";","");
					$("#"+$(objCheckbox).val()).remove();
				}
			}
			function selectMulitData()
			{
				//0员工ID,1员工代码,2员工姓名;0员工ID,1员工代码,2员工姓名
				if(parent.selectedEmployee!="")
				{
					if(confirm("确认选择？"))
					{
						var employees = parent.selectedEmployee.substring(0,parent.selectedEmployee.length-1);
						window.top.returnValue=employees;
						window.top.close();
					}
				}
				else
					alert("请选择员工！");
			}
			$(document).ready(function(){
				var type="${param.type}";
				if(type=="mulit")
				{
					var html="<table width=\"100%\"><tr><td width=\"100\">已选员工</td><td class=\"left_align\" id=\"empTd\">";
					if(parent.selectedEmployee!=null)
					{
						var data = parent.selectedEmployee.split(";");
						for(var i=0;i<data.length;i++)
						{
							if(data[i]!="")
							{
								var employeeInfo = data[i].split(",");
								var employeeId=employeeInfo[0];
								var employeeCode=employeeInfo[1];
								var employeeName=employeeInfo[2];
								html+="<span id=\""+employeeId+"\" title=\"点击取消选择该员工\" class=\"empSpan\">"+employeeName+"</span> ";
							}
						}
					}
					else
						parent.selectedEmployee="";
					html+="</td></tr></table>";
					$("#listTable").before(html);
				}
				
				//人员身份，根据需要传入可选择的人员身份，personnelIdentification=003001,003002,003003......
				var personnelIdentification = "${param.personnelIdentification}";
				//在岗状态
				var onJobSituation = "${param.onJobSituation}";
				if(personnelIdentification!="")
				{
					var s = personnelIdentification.split(",");
					$("#personnelIdentification").find("option").each(function(i){
						var test = false;
						for(var i=0;i<s.length;i++)
						{
							if($(this).val()==s[i]||$(this).val()=="")
							{
								test = true;
							}
						}
						if(!test)
							$(this.remove());
					});
				}
				if(onJobSituation!="")
				{
					var s = onJobSituation.split(",");
					$("#onJobSituation").find("option").each(function(i){
						var test = false;
						for(var i=0;i<s.length;i++)
						{
							if($(this).val()==s[i]||$(this).val()=="")
							{
								test = true;
							}
						}
						if(!test)
							$(this.remove());
					});
				}
				$("#companyName").getSuggest({
					jsonData : orgs,
					formatStr : ["orgId","orgName"],
					matchStr : ["jp","qp","orgId"],
					selectedMatch : new Array(["companyName","orgName"],["companyId","orgId"])
				});
				$("#employeeName").getSuggest({
					jsonData : emps,
					formatStr : ["employeeCode","employeeName"],
					matchStr : ["jp","qp","employeeCode"],
					selectedMatch : new Array(["employeeName","employeeName"],["employeeCode","employeeCode"])
				});
			});
			$(".empSpan").live("click",function(event){
				var spanObj = event.target;
				var employeeInfo = "";
				var employeeId = spanObj.id;
				var employees = parent.selectedEmployee.split(";");
				for(var i=0;i<employees.length;i++)
				{
					if(employees[i].indexOf(employeeId))
					{
						employeeInfo = employees[i];
						break;
					}
				}
				parent.selectedEmployee.replace(employeeInfo,"");
				$(spanObj).remove();
			});
		</script>
	</head>
	<body>
	<form action="listCommonEmployee.do?type=${param.type}&personnelIdentification=${param.personnelIdentification}&onJobSituation=${param.onJobSituation}" name="from1" method="post">
	<input type="hidden" name="jspPage" value="${jspPage}"/>
	<div id="body_div">
	<w:ShowTitle name="员工选择" useSubmitKey="false">
	<w:TitleButton funcName="查询" onClickFunction="_queryDivBg(this)" urlImg="${ctx}/images/main/query.png"/>
	</w:ShowTitle>
	<div id="body_content">
				<div id="queryDiv">
			<table width="100%" border="0">
				<tr>
					<td width="90">员工编号</td>
					<td class="left_align"><input type="text" name="empEmployee.employeeCode" id="employeeCode" value="${empEmployee.employeeCode}"/></td>
					<td>员工姓名</td>
					<td class="left_align"><input type="text" name="empEmployee.employeeName" id="employeeName" value="${empEmployee.employeeName}"/></td>
				</tr>
				<tr>
					<td>身份证号</td>
					<td class="left_align"><input type="text" name="empEmployee.idNumber" value="${empEmployee.idNumber}"/></td>
					<td>性别</td>
					<td class="left_align">
						<w:select name="empEmployee.employeeGender" value="${empEmployee.employeeGender}">
							<w:option optionLabel="请选择" optionValue=""></w:option>
							<w:option optionLabel="男" optionValue="男"></w:option>
							<w:option optionLabel="女" optionValue="女"></w:option>
						</w:select>
					</td>
				</tr>
				<tr>
					<td>出生日期</td>
					<td class="left_align" colspan="3">
					  	<input type="text" name="birthdayQueryStartDate" onFocus="new WdatePicker()" readOnly="readOnly" class="inputCal" value="${birthdayQueryStartDate}"/>
						至
						<input type="text" name="birthdayQueryEndDate" onFocus="new WdatePicker()" readOnly="readOnly" class="inputCal" value="${birthdayQueryEndDate}"/>
					</td>
				</tr>
				<tr>
					<td>所在单位</td>
					<td class="left_align">
						<input type="hidden" id="companyId" name="empEmployee.companyId" value="${empEmployee.companyId}"/>
		              	<input type="text" id="companyName" name="empEmployee.companyName" value="${empEmployee.companyName}"/>
					</td>
					<td>政治面貌</td>
					<td class="left_align">
						<w:select name="empEmployeeExtend.politicsStatus" value="${empEmployeeExtend.politicsStatus}">
							<w:option optionLabel="请选择" optionValue=""></w:option>
							<w:options options="${CodeDict}" optionLabel="codeName" optionValue="codeId" filterFieldName="parentCodeId" filterFieldValue="001"></w:options>
						</w:select>
					</td>
				</tr>
				<tr>
					<td>在岗情况</td>
					<td class="left_align">
						<w:select name="empEmployee.onJobSituation" styleId="onJobSituation" value="${empEmployee.onJobSituation}">
							<w:option optionLabel="在岗" optionValue="在岗"></w:option>
              				<w:option optionLabel="离岗" optionValue="离岗"></w:option>
						</w:select>
					</td>
					<td>人员身份</td>
					<td class="left_align">
						<w:select name="empEmployee.personnelIdentification" styleId="personnelIdentification">
							<w:option optionLabel="请选择" optionValue=""></w:option>
							<w:options options="${CodeDict}" optionLabel="codeName" optionValue="codeId" filterFieldName="parentCodeId" filterFieldValue="001"></w:options>
						</w:select>
					</td>
				</tr>
				<tr>
					 <td colspan="4">
						<input name="button" type="submit" class="btn_standard" onclick="" value="查询" />
						<input name="button" type="button" class="btn_standard" onclick="_cancelQuery()" value="取消" />
					</td>
				</tr>
			</table>
			</div>	
				<table width="100%" id="listTable" class="tableAutoWidth listTable" minWidth="900">
					<tr>
						<td class="td_title" width="30"><span onclick="checkAllEmp('employeeId');">选择</span></td>
						<td width="80" class="td_title">员工代码</td>
						<td width="80" class="td_title">姓名</td>
						<td class="td_title" width="40">性别</td>
						<td class="td_title" width="80">在岗情况</td>
						<td class="td_title" width="80">人员身份</td>
						<td class="td_title" >所在单位</td>
						<td class="td_title" >岗位</td>
						<td class="td_title" width="120">身份证号</td>
						<td class="td_title" width="80">出生日期</td>
					</tr>
					<c:forEach items="${datalist}" var="obj">
						<tr>
							<td>
								<c:if test="${(param.personnelIdentification eq '' or fn:indexOf(param.personnelIdentification,obj.personnelIdentification) ne -1) and (param.onJobSituation eq '' or fn:indexOf(param.onJobSituation,obj.onJobSituation) ne -1)}">
									<c:choose>
										<c:when test="${param.type eq 'mulit'}">
											<input type="checkbox" name="employeeId" value="${obj.employeeId},${obj.employeeCode},${obj.employeeName}" class="checkbox" onclick="employeeSelect(this)"/>
										</c:when>
										<c:otherwise>
											<a href="#" onclick="javascript:selectData('${obj.employeeId},${obj.employeeCode},${obj.employeeName},${obj.employeeGender},${obj.idNumber},${obj.companyId},${obj.companyName},${obj.deptId},${obj.deptName},${obj.postName},<fmt:formatDate value='${obj.employeeBirthday}' pattern="yyyy-MM-dd" />,${obj.onJobSituation},${obj.personnelIdentification}')">选择</a>
										</c:otherwise>
									</c:choose>
								</c:if>
							</td>
							<td width="50">${obj.employeeCode}</td>
							<td width="50"><a href="#" onclick="javascript:showData('${obj.employeeId}')">${obj.employeeName}</a></td>
							<td class="left_align">${obj.employeeGender}</td>
							<td class="left_align">${obj.onJobSituation}</td>
							<td class="left_align"><w:CodeDictOut value="${obj.personnelIdentification}"></w:CodeDictOut></td>
							<td class="left_align">${obj.companyName}</td>
							<td class="left_align">${obj.postName}</td>
							<td class="left_align">${obj.idNumber}</td>
							<td class="left_align"><fmt:formatDate value='${obj.employeeBirthday}' pattern="yyyy-MM-dd" /></td>
						</tr>
					</c:forEach>
				</table>
				<w:spPage />
			</div>
		</div>	
		</form>
	</body>
</html>